package com.example.boot6rabbitmq.config;

import com.alibaba.fastjson.JSONObject;
import com.example.boot6rabbitmq.entity.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class RabbitmqSender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    private RabbitTemplate rabbitTemplate;


    public void sendMessage(String exchange, String roukekey, Message content) {
        try {
            log.info("============发送消息=========" + content);
            amqpTemplate.convertAndSend(exchange, roukekey, JSONObject.toJSONString(content));
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void sendMessageConfirm(String exchange, String roukekey, Message content) {
        try {
            log.info("======1======发送消息=====confirm====" + content);
            rabbitTemplate.convertAndSend(exchange, roukekey, JSONObject.toJSONString(content));
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
